package com.scraper.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.scraper.dao.SaleObjectDAO;
import com.scraper.model.OperationType;
import com.scraper.model.SaleObject;
import com.scraper.service.SaleObjectManager;

public class SalaObjectManagerImpl implements SaleObjectManager{

	private SaleObjectDAO saleObjectDAO;
	
	public void create(SaleObject saleObject) {
		getSaleObjectDAO().saveOrUpdate(saleObject);
	}

	public void delete(SaleObject saleObject) {
		getSaleObjectDAO().delete(saleObject);
	}

	public List<SaleObject> getSaleObjectsList() {
		return getSaleObjectDAO().list();
	}

	public SaleObject getSaleOnjectByID(Integer id) {
		return getSaleObjectDAO().get(id);
	}

	public void setSaleObjectDAO(SaleObjectDAO saleObjectDAO) {
		this.saleObjectDAO = saleObjectDAO;
	}

	public SaleObjectDAO getSaleObjectDAO() {
		return saleObjectDAO;
	}

	public List<SaleObject> getSaleObjectsByOperationType(
			OperationType operationType) {
		List<SaleObject> saleObjects = new ArrayList<SaleObject>();
		for (int i = 0; i < this.saleObjectDAO.list().size() ; i++) {
			SaleObject saleObject = this.saleObjectDAO.get(i);
			if(saleObject.getOperationType()==operationType){
				saleObjects.add(saleObject);
			}
		}
		return saleObjects;
	}

}
